#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		int a,b;
		cin >> a >> b;
		int g=a,h=b;
		int e=0;
		int f=0;
		while(g!=0)
		{
			e=e+g%10;
			g=g/10;
		}
		while(h!=0)
		{
			f=f+h%10;
			h=h/10;
		}
		cout << e << " " << f << endl;
		cout << a%f << " " << b%e << endl;
		if(a%f==0&&b%e!=0)
		{
			cout << "A" << endl;
		}
		if(a%f!=0&&b%e==0)
		{
			cout << "B" << endl;
		}
		if((a%f!=0&&b%e!=0)||(a%f==0&&b%e==0))
		{
			if(a>b)
			{
				cout << "A" << endl;
			}
			else if(b>a)
			{
				cout << "B" << endl;
			}
		}
	}
	return 0;
}
